﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class Admin_ucControl_ucMenuParrent : System.Web.UI.UserControl
{
    CategoryParrentDAO MenuParrentDAO = new CategoryParrentDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadMenuParrent();
            string id = Request.QueryString["id"];
            if (id != null)
            {
                LoadDetail_MenuParrent();
            }
        }
    }

    public void LoadDetail_MenuParrent()
    {
        string id = Request.QueryString["id"];
        CategoryParrent menuParrent = MenuParrentDAO.GetMenuParrent_ById(Global.ConvertToInt(id));
        txtMenuParrent.Text = menuParrent.CategoryParrName;

    }
   

    private void LoadMenuParrent()
    {
        grdMenuParrent.DataSource = MenuParrentDAO.GetMenuParrent();
        grdMenuParrent.DataBind();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        bool flag = false;
        try
        {
            CategoryParrent MenuParrent = new CategoryParrent();
            MenuParrent.CategoryParrName = txtMenuParrent.Text.Trim();

            if (id == "" || id == null)
            {
                //MenuParrent.IDCateParrent = 0;
                MenuParrentDAO.InsUp_MenuParrent(MenuParrent, 1);
            }
            else
            {
                MenuParrent.IDCateParrent = Global.ConvertToInt(id);
                MenuParrentDAO.InsUp_MenuParrent(MenuParrent, 2);
            }
            flag = true;
            txtMenuParrent.Text = string.Empty;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        if (flag)
        {
            LoadMenuParrent();
        }
    }
}
